package com.example.bms.controller;
import com.example.bms.entity.Admin;
import com.example.bms.entity.ApiResult;
import com.example.bms.serviceimpl.AdminServiceImpl;
import com.example.bms.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @apiNote 用于实现超级管理员的增删改查
 * @author
 * @email 2837136899@qq.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST,RequestMethod.PUT,RequestMethod.DELETE})
public class AdminController {

    private AdminServiceImpl adminService;
    @Autowired
    public AdminController(AdminServiceImpl adminService){
        this.adminService = adminService;
    }


    /**
     * @apiNote 用于查询所有超级管理员的基本信息
     * @author
     * @email 2837136899@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/admins")
    public ApiResult findAll(){
        System.out.println("查询全部");
        return ApiResultHandler.success(adminService.findAll());
    }


    /**
     * @apiNote 根据adminId查询超级管理员信息
     * @author
     * @param adminId 超级管理员Id
     * @email 2837136899@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/admin/{adminId}")
    public ApiResult findById(@PathVariable("adminId") Integer adminId){
        System.out.println("根据ID查找");
        return ApiResultHandler.success(adminService.findById(adminId));
    }


    /**
     * @apiNote 根据adminId删除超级管理员
     * @author
     * @param adminId 超级管理员Id
     * @email 2837136899@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @DeleteMapping("/admin/{adminId}")
    public ApiResult deleteById(@PathVariable("adminId") Integer adminId){
        adminService.deleteById(adminId);
        return ApiResultHandler.success();
    }


    /**
     * @apiNote 根据adminId修改超级管理员的信息
     * @author
     * @param admin 超级管理员的对象实体类
     * @param adminId 超级管理员Id
     * @email 2837136899@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PutMapping("/admin/{adminId}")
    public ApiResult update(@PathVariable("adminId") Integer adminId, Admin admin){
        return ApiResultHandler.success(adminService.update(admin));
    }


    /**
     * @apiNote  用于增加一个超级管理员
     * @author
     * @param admin 超级管理员的对象实体类
     * @email 2837136899@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PostMapping("/admin")
    public ApiResult add(Admin admin){
        return ApiResultHandler.success(adminService.add(admin));
    }
}
